package com.example.chatrecommendation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.chatrecommendation.bean.dto.RadarUpdateDTO;
import com.example.chatrecommendation.bean.entity.Radar;
import com.example.chatrecommendation.bean.vo.RadarVO;
import com.example.chatrecommendation.mapper.RadarMapper;
import com.example.chatrecommendation.service.RadarService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 *
 * @description 针对表【radar(雷达图)】的数据库操作Service实现
 * @Date 2024-03-07 17:22:50
 * @author Jasmine-drs
 */
@Service
public class RadarServiceImpl extends ServiceImpl<RadarMapper, Radar> implements RadarService{

    private final RadarMapper radarMapper;

    public RadarServiceImpl(RadarMapper radarMapper) {
        this.radarMapper = radarMapper;
    }

    @Override
    public RadarVO getRadar(Integer userId) {

//        Integer currentId = BaseContext.getCurrentId();
//        currentId = 123456;
        Radar radar = radarMapper.getRadar(userId);

        RadarVO radarVO = RadarVO.builder()
                .studentId(radar.getStudentId())
                .perceive(radar.getPerceive())
                .innovate(radar.getInnovate())
                .practice(radar.getPractice())
                .expression(radar.getExpression())
                .criticize(radar.getCriticize())
                .build();
        return radarVO;
    }

    @Override
    public void update(RadarUpdateDTO radarUpdateDTO, Integer currentId) {
//        Integer currentId = BaseContext.getCurrentId();
//        currentId = 123456;

        Radar radar = Radar.builder()
                .studentId(currentId)
                .innovate(radarUpdateDTO.getInnovate())
                .practice(radarUpdateDTO.getPractice())
                .expression(radarUpdateDTO.getExpression())
                .criticize(radarUpdateDTO.getCriticize())
                .perceive(radarUpdateDTO.getPerceive())
                .updateTime(LocalDateTime.now())
                .build();
        radarMapper.update(radar);
    }
}




